public class test02 {
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode() {}
     *     TreeNode(int val) { this.val = val; }
     *     TreeNode(int val, TreeNode left, TreeNode right) {
     *         this.val = val;
     *         this.left = left;
     *         this.right = right;
     *     }
     * }
     */
        public List<List<Integer>> levelOrderBottom(TreeNode root) {
            //list反转
            List<List<Integer>> res = new ArrayList<>();
            Queue<TreeNode> queue = new LinkedList<>();
            if(root==null){
                return res;
            }
            queue.offer(root);
            while(!queue.isEmpty()){
                int len = queue.size();
                List<Integer> list = new ArrayList<>();
                for(int i = 0;i<len;i++){
                    TreeNode tmpNode = queue.poll();
                    list.add(tmpNode.val);
                    if(tmpNode.left!=null){
                        queue.offer(tmpNode.left);
                    }
                    if(tmpNode.right!=null){
                        queue.offer(tmpNode.right);
                    }
                }
                res.add(list);
            }
            Collections.reverse(res);
            return res;
        }
}
